package com.example.footclassfiydome.controller;

import ai.djl.modality.Classifications;
import ai.djl.translate.TranslateException;
import com.example.footclassfiydome.service.InterfenceService;
import com.example.footclassfiydome.service.TrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * Created by lilijava
 * on 2024/12/25
 * <p>
 * on  foot-classfiy-dome
 */
@RestController
public class DeepLearnRestContorller {
    @Autowired
    TrainService trainService;
    @Autowired
    InterfenceService interfenceService;
    // 训练模型
    @GetMapping("/train")
    public String train() throws TranslateException, IOException {

        trainService.train("build/ut-zap50k-images-square","build/models");
//        CompletableFuture.runAsync(()->{
//            try{
//            trainService.train("build/ut-zap50k-images-square","build/models");
//            }catch (TranslateException | IOException e) {
//                throw new RuntimeException(e);
//            }
//        });
        return "正在训练";
    }
    @PostMapping("/inference")
    public Classifications inference(@RequestPart("file") MultipartFile image) throws IOException {
        //Shoes鞋	Sandals凉鞋	Slippers拖鞋	Boots靴子
        String path= String.valueOf(image);
        Classifications predict = interfenceService.predict(path);
        System.out.println( "predict:"+predict);
        return predict;
    }
}
